package cn.com.oceansoft.business.danger.service;

import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.base.entity.Result;
import cn.com.oceansoft.business.danger.entity.*;
import cn.com.oceansoft.business.danger.persistence.IDangertContentMapper;
import cn.com.oceansoft.nos.common.util.web.PageUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lenovo on 2018/5/3.
 */
@Service
@Transactional
public class DangerContentServiceImpl implements IDangerContentService {
    @Resource
    private IDangertContentMapper dangertContentMapper;
    @Override
    public Pager<DangerContent> getNrList(Query query) {
        try{
            PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
            Page<DangerContent> page = (Page<DangerContent>) dangertContentMapper.getNrList(query);
            return PageUtil.page2pager(page, query);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public DangerContent getInfoDetail(DangerContent dangerContent) {
        try{
            return dangertContentMapper.getInfoDetail(dangerContent);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<DangerContent> getInfoPic(DangerContent dangerContent) {
        try{
            return dangertContentMapper.getInfoPic(dangerContent);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<CollecterInfo> getDictList(DangerContent dangerContent) {
        try{
            return dangertContentMapper.getDictList(dangerContent);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Flowinfo> getInfoDetailLz(Flowinfo flowinfo) {
        try{
            return dangertContentMapper.getInfoDetailLz(flowinfo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<DangerContent> getInfoPicfk(DangerContent dangerContent) {
        try{
            return dangertContentMapper.getInfoPicfk(dangerContent);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Flowinfo> getInfoDetailJg(Flowinfo flowinfo) {
        try{
            return dangertContentMapper.getInfoDetailJg(flowinfo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Flowinfo getInfoDetailOne(Flowinfo flowinfo) {
        try{
            return dangertContentMapper.getInfoDetailOne(flowinfo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Pager<DangerContent> getNrListWithName(Query query) {
        try{
            PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
            Page<DangerContent> page = (Page<DangerContent>) dangertContentMapper.getNrListWithName(query);
            return PageUtil.page2pager(page, query);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Result submitFlowInfo(Flowinfo flowinfo) {
        int rt=0;
        try{
            dangertContentMapper.updateflowZt(flowinfo);
        }catch (Exception e){
            e.printStackTrace();
        }
        rt = dangertContentMapper.submitFlowInfo(flowinfo);
        if (rt > 0) {
            return new Result(Result.SUCC, "保存成功");
        } else {
            return new Result(Result.FAILURE, "保存失败");
        }
    }

    @Override
    public Flowinfo getFlowInfo(String id, String i) {
        return dangertContentMapper.getFlowInfo(id,i);
    }

    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void updateCfZg(String id,String dangerid) {
        try{
            dangertContentMapper.updateCf(id);
            dangertContentMapper.updateZg(id);
            dangertContentMapper.updateImg(dangerid);

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public List<Flowinfo> getInfoDetailOneList(Flowinfo flowinfo) {
        try{
            List<Flowinfo> list = dangertContentMapper.getInfoDetailOneList(flowinfo);
            for(Flowinfo f :list){
                f.setCfcs(dangertContentMapper.getCfcs(f.getId()));
                f.setZgcs(dangertContentMapper.getZgcs(f.getId()));
            }
            return list;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Pager<DangerContent> getNrListWithNameQ(Query query) {
        try{
            PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
            Page<DangerContent> page = (Page<DangerContent>) dangertContentMapper.getNrListWithNameQ(query);
            return PageUtil.page2pager(page, query);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Flowinfo> getListFlowInfo(Flowinfo flowinfo) {
        List<Flowinfo> flowInfo = dangertContentMapper.getListFlowInfo(flowinfo);
        return flowInfo;
    }

    @Override
    public Cfcs getCfcs(String id) {
        return dangertContentMapper.getCfcs(id);
    }

    @Override
    public Zgcs getZgcs(String id) {
        return dangertContentMapper.getZgcs(id);
    }

    @Override
    public List<Attach> getPicFK(String id) {
        try{
            return dangertContentMapper.getPicFK(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Pager<DangerContent> getTypeDetailList(Query query) {
        try{
            PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
            Page<DangerContent> page = (Page<DangerContent>) dangertContentMapper.getTypeDetailList(query);
            return PageUtil.page2pager(page, query);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Pager<DangerContent> xxtjDetailList(Query query) {

        PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
        Page<DangerContent> page = (Page<DangerContent>) dangertContentMapper.xxtjDetailList(query);
        return PageUtil.page2pager(page, query);
    }

    @Override
    public Pager<DangerContent> getQytjDetail(Query query) {
        try{
            PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
            Page<DangerContent> page = (Page<DangerContent>) dangertContentMapper.getQytjDetail(query);
            return PageUtil.page2pager(page, query);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
